/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import model.*;
import helper.*;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "vmb")
@SessionScoped
public class VacancyManagedBean {
    @EJB
    private DepartmentFacade departmentFacade;
    
    @EJB
    private VacancyFacade vacancyFacade;
    private Vacancy vac = new Vacancy();
    private String message = new String();

    public String getMessage() {
        return message;
    }
    
    private String DepartmentID;

    public String getDepartmentID() {
        return DepartmentID;
    }

    public void setDepartmentID(String DepartmentID) {
        this.DepartmentID = DepartmentID;
    } 
    
    Date date =new Date();

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
    

    public VacancyFacade getVacancyFacade() {
        return vacancyFacade;
    }

    public void setVacancyFacade(VacancyFacade vacancyFacade) {
        this.vacancyFacade = vacancyFacade;
    }

    public Vacancy getVac() {
        return vac;
    }

    public void setVac(Vacancy vac) {
        this.vac = vac;
    }
   
    public VacancyManagedBean() {
    }
 public String editvac(){
        this.vacancyFacade.edit(this.vac);
        return "List";
    }
    public String deletevacancy(Vacancy v){
        String page = "";
        try {
            this.vacancyFacade.remove(v);
            page ="List";
        } catch (Exception e) {
            this.message ="Delete not found";         
        }
        
        return page;
    }
    public List<Vacancy> vacancyList(){    
        return this.vacancyFacade.findAll();
    }
    public String createvac(){
       
        String vacancyID= generateID();
        try
        {
            this.vac.setVacancyID(vacancyID);
            this.vac.setDepartmentID(this.departmentFacade.find(this.DepartmentID));
            this.vac.setCreatedDate(new Date());
         this.vacancyFacade.create(this.vac);
         
        }
        catch(Exception ex)
        {
            
        }                
        
        return "List";
        
    }
    public String vacEdit(Vacancy v){
        this.vac = v;
        return "Edit";
    }
    public String vacView(Vacancy v){
        this.vac = v;
        return "View";
    }
    private String generateID() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        
        return "V" + sdf.format(new Date());
    }
    
    
}
